package 数组;

import java.util.Arrays;
import java.util.Random;

public class 打乱数组 {

    int[] array;
    int[] original;

    public 打乱数组(int[] array) {
        array = array;
        original = array.clone();
    }

    /**
     * Resets the array to its original configuration and return it.
     */
    public int[] reset() {
        array = original;
        original = original.clone();
        return original;
    }


    Random rand = new Random();

    /**
     * Returns a random shuffling of the array.
     */
    public int[] shuffle() {
        for (int i = 0; i < array.length; i++) {
            int randIndex = rand.nextInt(array.length - i) + i;
            int temporary = array[i];
            array[i] = array[randIndex];
            array[randIndex] = temporary;
        }
        return array;
    }
}
